var e, t = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../@babel/runtime/regenerator")), a = require("../../../@babel/runtime/helpers/asyncToGenerator"), r = require("../../../utils/DPagination").default, s = require("../common"), o = s.getProjectNameLang, i = s.getLocation, n = getApp(), c = n.getNetAddresss("plugin.store-projects.frontend.project-order.get-un-finish-list"), l = n.getNetAddresss("plugin.store-projects.frontend.project-order.get-finish-list"), u = new r("projects"), g = null;

Page({
    data: {
        currentShowPageTab: "0",
        projects: {},
        projectCount: 0,
        projectNameLang: o(),
        showGivePop: !1,
        giveInfo: {},
        Location: {},
        giveUserId: "",
        giveNum: "",
        nickname: "",
        errorFlag: !1,
        errorMsg: "",
        timeStyle: "0",
        addressValue: "",
        paramsData:{placeholder:'搜索',color:'transparent',color2:'#f14e4e'}
    },
    onLoad: (e = a(t.default.mark(function e(a) {
        var r;
        return t.default.wrap(function(e) {
            for (;;) switch (e.prev = e.next) {
              case 0:
                return a.Location && (r = JSON.parse(a.Location), console.log(r), this.setData({
                    Location: r
                })), u.bind(this), e.next = 4, i();

              case 4:
                g = e.sent, this.getProjects();

              case 6:
              case "end":
                return e.stop();
            }
        }, e, this);
    })), function(t) {
        return e.apply(this, arguments);
    }),
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {
        u.clean();
    },
    onPullDownRefresh: function() {
        u.clean(), this.getProjects();
    },
    onReachBottom: function() {
        this.getProjects();
    },
    onShareAppMessage: function() {},
    switchPageTabs: function(e) {
        var t = e.detail.name;
        this.setData({
            currentShowPageTab: t
        }), u.clean(), this.getProjects();
    },
    timeSort: function(e) {
        var t = e.currentTarget.dataset.val, a = this.data.timeStyle;
        a = !0 === t ? 2 == a ? 3 : 2 : 0 == a ? 1 : 0, this.setData({
            timeStyle: a
        }), u.clean(), this.getProjects();
    },
    getProjects: function() {
        var e = this;
        if (!u.loading && !u.finished) {
            u.loading = !0;
            var t = c, a = n.qqMapTransBMap(parseFloat(g.point.lng), parseFloat(g.point.lat)), r = {
                page: u.loadPage,
                lat: a.lat,
                lng: a.lng
            }, s = this.data.Location;
            Object.keys(s).length > 0 ? (r.lat = s.latitude, r.lng = s.longitude, this.setData({
                addressValue: s.message
            }), console.log(this.data.Location, 9898)) : this.setData({
                addressValue: g.address
            }), "1" === this.data.currentShowPageTab ? t = l : r.orderby = this.data.timeStyle, 
            wx.showLoading(), n._getNetWork({
                url: t,
                data: r,
                success: function(t) {
                    var a = t.data, r = a.data, s = a.result, o = a.msg;
                    u.loading = !1, wx.stopPullDownRefresh(), wx.hideLoading(), 0 != s ? ((r.current_page == r.last_page || r.data.length < r.per_page) && (u.finished = !0), 
                    u.push(r.data), e.setData({
                        projectCount: u.length
                    })) : wx.showToast({
                        title: o,
                        icon: "none"
                    });
                }
            });
        }
    },
    tapBtnGive: function(e) {
        var t = e.currentTarget.dataset.item;
        this.setData({
            showGivePop: !0,
            giveInfo: t
        });
    },
    tolink: function(e) {
        console.log(e);
        var t = e.currentTarget.dataset.url;
        wx.navigateTo({
            url: t
        });
    },
    closeGivePop: function() {
        this.setData({
            showGivePop: !1
        });
    },
    giveProject: function() {
        var e = this;
        if (this.data.giveUserId) if (this.data.errorFlag) this.setData({
            errorMsg: "查无此用户",
            errorFlag: !0
        }); else if (this.data.giveNum) if (this.data.giveInfo.rest_count < this.data.giveNum) this.setData({
            errorNum: "输入转赠次数大于拥有的次数"
        }); else {
            var t = n.getNetAddresss("plugin.store-projects.frontend.project-order.transfer");
            n._getNetWork({
                url: t,
                data: {
                    id: this.data.giveInfo.id,
                    transfer_uid: this.data.giveUserId,
                    transfer_count: this.data.giveNum
                },
                success: function(t) {
                    var a = t.data;
                    console.log(a.msg), n.tips(a.msg), 1 == a.result && (e.closeGivePop(), u.clean(), 
                    e.getProjects());
                }
            });
        } else this.setData({
            errorNum: "转增次数不能为空"
        }); else this.setData({
            errorFlag: !0,
            errorMsg: "请输入用户"
        });
    },
    throttleFn: function(e) {
        var t = this, a = e.detail;
        this.data.giveUserId = a, this.data.errorFlag = !0, this.timeoutId && clearTimeout(this.timeoutId), 
        this.timeoutId = setTimeout(function() {
            t.searchUser(a);
        }, 1e3);
    },
    searchUser: function(e) {
        var t = this, a = n.getNetAddresss("member.member.memberInfo");
        console.log(a), n._getNetWork({
            url: a,
            data: {
                uid: e
            },
            success: function(a) {
                var r = a.data;
                1 == r.result && null != r.data ? t.setData({
                    nickname: r.data.nickname,
                    errorFlag: !1,
                    giveUserId: e
                }) : t.setData({
                    errorFlag: !0,
                    errorMsg: "查无此用户"
                });
            },
            fail: function() {
                t.setData({
                    giveUserId: "",
                    errorFlag: !0,
                    errorMsg: "查无此用户"
                });
            }
        });
    },
    changeNumInput: function(e) {
        console.log(e);
        var t = this.data.giveNum, a = "";
        t <= 0 ? a = "转增次数不能为空" : this.data.giveInfo.rest_count < t && (a = "输入转赠次数大于拥有的次数"), 
        this.setData({
            errorNum: a
        });
    }
});